import Router from 'koa-router'
import config from '../config'
import sha1 from 'sha1'

export const router = app => {
    const router = new Router()
// 这里get和post的区别？
    router.get('/wechat-hear', (ctx, next) => {
        const token = config.wechat.token
        const {
            signature,
            nonce,
            timestamp,
            echostr
        } = ctx.query
        const str = [token, timestamp, nonce].sort().join('') // 排序
        const sha = sha1(str) // 加密
        console.log(ctx.query)
        console.log(echostr)
        ctx.body = sha===signature? echostr: 'failed'
    })
    /* router.post('/wechat-hear', (ctx, next) => {

    }) */
    app.use(router.routes())
    app.use(router.allowedMethods())
}